package com.boge.modules.ssgf.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;

import com.boge.common.utils.ShiroUtils;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.boge.modules.ssgf.entity.ReservationEntity;
import com.boge.modules.ssgf.service.ReservationService;
import com.boge.common.utils.PageUtils;
import com.boge.common.utils.R;



/**
 * 
 *
 * @author boge
 * @email dengpbs@163.com
 * @date 2024-12-20 23:40:41
 */
@RestController
@RequestMapping("ssgf/reservation")
public class ReservationController {
    @Autowired
    private ReservationService reservationService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("ssgf:reservation:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = reservationService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 获取当前用户的代付款的订单信息
     * 状态码 为3
     * 接口前缀：/ssgf/reservation
     */
    @RequestMapping("/getPayOrder")
    //@RequiresPermissions("ssgf:reservation:list")
    public R getPayOrder(@RequestParam Map<String, Object> params){
        PageUtils page = reservationService.queryPagePayOrder(params);

        return R.ok().put("page", page);
    }

    /**
     * 更新订单状态为 支付完成
     * 需要传递 预约记录的id
     */
    @RequestMapping("/updatePayOrder")
    //@RequiresPermissions("ssgf:reservation:save")
    public R updatePayOrder(@RequestBody ReservationEntity reservation){
        ReservationEntity entity = reservationService.getById(reservation.getId());
        entity.setStatus(4);
        reservationService.updateById(entity);
        return R.ok();
    }




    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("ssgf:reservation:info")
    public R info(@PathVariable("id") Integer id){
		ReservationEntity reservation = reservationService.getById(id);

        return R.ok().put("reservation", reservation);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("ssgf:reservation:save")
    public R save(@RequestBody ReservationEntity reservation){
        Long userId = ShiroUtils.getUserId();
        reservation.setUserId(userId.intValue());
        reservationService.save(reservation);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("ssgf:reservation:update")
    public R update(@RequestBody ReservationEntity reservation){
		reservationService.updateById(reservation);

        return R.ok();
    }

    /**
     * 删除 updateQd
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("ssgf:reservation:delete")
    public R delete(@RequestBody Integer[] ids){
		reservationService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }


    @RequestMapping("/updateQd")
    //@RequiresPermissions("ssgf:reservation:delete")
    public R updateQd(@RequestBody Integer id){
        ReservationEntity entity = reservationService.getById(id);
        Long userId = ShiroUtils.getUserId();
        entity.setWxUser(userId.intValue());
        entity.setStatus(1);
        entity.setWxTime(new Date());
        reservationService.updateById(entity);
        return R.ok();
    }

    @RequestMapping("/updateOver")
    //@RequiresPermissions("ssgf:reservation:delete")
    public R updateOver(@RequestBody Integer id){
        ReservationEntity entity = reservationService.getById(id);
        Long userId = ShiroUtils.getUserId();
        entity.setStatus(3);
        reservationService.updateById(entity);
        return R.ok();
    }

    @RequestMapping("/updateMoney")
    //@RequiresPermissions("ssgf:reservation:delete")
    public R updateMoney(@RequestBody ReservationEntity entity){
        Integer newMoney = entity.getMoney();
        entity = reservationService.getById(entity.getId());
        entity.setStatus(2);
        entity.setMoney(newMoney);
        reservationService.updateById(entity);
        return R.ok();
    }


}
